const mysql2 = require('mysql2');
const config = require('./config');


const connections = mysql2.createPool({
    host: MYSQL_HOST,
    port: MYSQL_PORT,
    database: MYSQL_DATABASE,
    user: MYSQL_USER,
    password: MYSQL_PASSWORD
})

connections.getConnection((err, conn) => {
    conn.connect((err) => {
        if (err) {
          console.log("数据库连接失败:", err);
          return;
        }
        console.log("数据库连接成功");
    })
});

module.exports = connections.promise(); //因为后面操作数据库都是使用promise方式操作，所以现在可以先导出